//JSON数据源
https://api.douban.com/v2/movie/top250
    //JSON数据格式化
    https://tool.oschina.net/codeformat/json
var xmlhttp;
if(window.XMLHttpRequest){
    //IE7+,FireFox,Chrome,Opera,Safari
    XMLHttp=new XMLHttpRequest();
}else{
    //IE6
    xmlhttp=new ActiveXObject("Micosoft.XMLHTTP");
}

var news_content=document.getElementById("news_content");

//HTTP时无状态，定义一些状态值描述当前HTTP的性质
//404（not found）200(ok) 50x(服务器应用程序错误)
//定义回调函数
xmlhttp.onreadystatechange=funcation(){
    if(xmlhttp.readyState === 4 && xmlhttp.status ===200){
        //news_content.innerHTML=xmlhttp.readAsText;
        //JSON.parse()把文本数据解析为Json对象
        news_content.innerHTML=xmlhttp.readAsText;
        showJson(JSON.parse(xmlhttp.readAsText));
    }
}
//HTTP访问方法：GET  POST...
//xmlhttp.open("GET","https://api.douban.com/v2/movie/top250",true);
xmlhttp.open("GET","top250.json",true);
xmlhttp.send();

function showJson(jsonData) {
    document.getElementById("title").innerText=jsonData.title;
    var tempHtml ="";
    for (var i = 0; i < 10; i++) {
                // tempHtml += "<li>" + jsonData.subjects[i].title + "</li>\n";
                   tempHtml += "<li>";
                tempHtml += jsonData.subjects[i].title;
                tempHtml += "<img src=\"";
                tempHtml += jsonData.subjects[i].images.medium;
               tempHtml += "\" alt=\"";
                tempHtml += jsonData.subjects[i].title;
                tempHtml += "\">";
                tempHtml += "</li>";
         }
        document.getElementById("news_list").innerHTML = tempHtml;
}